﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using IRIS.Models;
using System.Web.Routing;
using System.Web.Mvc.Ajax;

namespace IRIS.Controllers
{
    public class SearchController : Controller
    {
        DataRepo m_Db = new DataRepo();
        //
        // GET: /Search/?theSearchString=HerpaDerp
        [HttpPost]
        public ActionResult Index(string theSearchString)
        {
            if (theSearchString == null)
                return View("NotFound");
            var query = m_Db.search();
            
            var articles = from c in query.m_Articles
                           where c.ContentTitle.ToLower().Contains(theSearchString.ToLower())
                           && c.ContentText.ToLower().Contains(theSearchString.ToLower())
                           select c;
            var news = from c in query.m_News
                       where c.ContentTitle.ToLower().Contains(theSearchString.ToLower())
                             && c.ContentText.ToLower().Contains(theSearchString.ToLower())
                       select c;
            var events = from c in query.m_Events
                         where c.Description.ToLower().Contains(theSearchString.ToLower())
                               && c.Title.ToLower().Contains(theSearchString.ToLower())
                         select c;
            var model = new SearchViewModel {m_Articles = articles, m_Events = events, m_News = news};

            return View(model); 
        }
    }
}
